package com.moyq5.permit.center.feign.server.jackson.filter;

import java.lang.reflect.Method;
import java.util.HashSet;
import java.util.Set;

import com.moyq5.mvc.framework.utils.StringUtils;
import com.moyq5.permit.center.bean.entity.SysAdmin;
import com.fasterxml.jackson.databind.ser.FilterProvider;
import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;

/**
 * @author Moyq5's MvcMaker Tools
 */
public abstract class SysAdminFilter {

	public static FilterProvider get(String filter) {
		if (StringUtils.isEmpty(filter)) {
				return get();
		}
		try {
				Method method = SysAdminFilter.class.getMethod("getWith" + String.valueOf(filter.charAt(0)).toUpperCase() + filter.substring(1));
				return (FilterProvider)method.invoke(null);
		} catch (Exception e) {
				return get();
		}
	}
	
	public static Set<String> baseFields() {
		final Set<String> admin = new HashSet<String>();
		admin.add("adminId");
		admin.add("platforms");
		admin.add("name");
		admin.add("named");
		admin.add("pwd");
		admin.add("salt");
		admin.add("nickname");
		admin.add("realName");
		admin.add("mobile");
		admin.add("portrait");
		admin.add("sex");
		admin.add("curTime");
		admin.add("preTime");
		admin.add("addTime");
		return admin;
	}

	public static FilterProvider getId() {
		final Set<String> admin = new HashSet<String>();
		admin.add("adminId");
		
		return new SimpleFilterProvider().addFilter(
				SysAdmin.class.getSimpleName(),
				SimpleBeanPropertyFilter.filterOutAllExcept(admin));
	}

	public static FilterProvider get() {
		return new SimpleFilterProvider().addFilter(
				SysAdmin.class.getSimpleName(),
				SimpleBeanPropertyFilter.filterOutAllExcept(baseFields()));
	}

}
